Preview - Programming: It's For Everyone!

Bonus: Conditionals - Making a Smarter Turtle


If you still have time, let's cover one more concept: conditionals.

conditional is basically the computational equivalent of an "if - then" statement. For instance, if there's a chair beneath me, then I can take a seat. Conditionals are very powerful in programming because they allow us to perform different actions based on some condition.

Before, our amazing-turtle-saving-maze-program only applied to a single map at a time because we were just analyzing the situation ourselves and giving our turtle buddy explicit directions. What if our turtle buddy could do that sort of analysis by itself? Could we write an program that could solve any map?

Below you'll see our familiar turtle maze, complete with a Programming Canvas to the right with some additional blocks. The additional blocks are:

if patch-ahead: this block is a conditional that allows your turtle to check for one of four conditions. Is this patch ahead the goal? lava? safe? or an edge? This block will execute commands inside of it only if the condition is met.

maybe: this is a different type of conditional that depends on random chance. Your turtle will randomly choose to follow the commands inside of this block according to the probability you select.

randomly pick: this is yet another conditional that you might think of as an if-else statement. Your turtle will basically flip a coin. If heads, it will do the first thing. Otherwise, it will do the second thing.

Like our drawing turtle, your turtle will continuously run "to move" function you provide it until it meets an untimely doom or reaches the safety of the violet patch..

Using the provided blocks, try and come up with a to move program that can solve ANY of the mazes you throw at it. If your program successfully solves one puzzle, hit RESET and then run your program again.

 


Questions

Please answer the questions below.

Is it possible to get a generalized solution without using one of the "chance" blocks (e.g. randomly pick and maybe)? Why or why not?


How did you go about writing your program? Trial and error? Did you plan it out first? Describe your process.


While our turtle buddy being able to make a decision based on the patch ahead is a big step in the right direction, what other sort of "knowledge" do you think woul be nice for the turtle to be able to have to make a decision on where and how to move?


Reflect on what you've done in the past hour or so. Did you learn something new about programming? What was most difficult? What came most easily?


Notes

These notes will appear on every page in this lesson so feel free to put anything here you'd like to keep track of.